import type {
  BaseEntity,
  CheckedSelectTree,
  ID,
  IDS,
  PageQuery,
  PageResult,
} from '#/api/common';

import { requestClient } from '#/api/request';

const baseUrl = `/ur_biz/sys_tenant/package`;

/**
 * 租户套餐
 */
export interface SysTenantPackage extends BaseEntity {
  packageId: ID;
  packageName: ID;
  status: string;
  menuIds: string[];
  isMenuDisplay: boolean;
  remark: string;
}

// 查询租户套餐列表
export function listTenantPackage(query: PageQuery) {
  return requestClient.get<PageResult<SysTenantPackage>>(`${baseUrl}/list`, {
    params: query,
  });
}

// 根据套餐ID查询菜单列表树
export function menuTreeSelect(packageId: ID) {
  return requestClient.get<CheckedSelectTree>(
    `${baseUrl}/menu_checked_select_tree/${packageId ?? ''}`,
  );
}

// 查询租户套餐详细
export function getTenantPackage(packageId: ID) {
  return requestClient.get<SysTenantPackage>(`${baseUrl}/${packageId}`);
}

// 新增租户套餐
export function addTenantPackage(data: any) {
  return requestClient.post(`${baseUrl}/add`, data);
}

// 修改租户套餐
export function editTenantPackage(data: any) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

// 修改租户套餐状态
export function changeStatus(id: ID, status: string) {
  return requestClient.post(`${baseUrl}/edit_status`, {
    id,
    status,
  });
}

// 删除租户套餐
export function delTenantPackage(packageIds: IDS) {
  return requestClient.post(`${baseUrl}/remove`, packageIds);
}
